package com.swxy.club.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swxy.club.dto.dt.ClubApprovalQueryDTO;
import com.swxy.club.dto.Vo.ClubApprovalDetailVO;
import com.swxy.club.dto.Vo.ClubApprovalVO;
import com.swxy.club.result.Result;
import com.swxy.club.service.ClubApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 社团申请记录表 前端控制器
 * </p>
 *
 * @author dyh
 * @since 2025-04-23
 */
@RestController
@RequestMapping("/api/approvals")
@Api(tags = "社团申请记录表")
@RequiredArgsConstructor
public class ClubApplicationController {

    private final ClubApplicationService clubApplicationService;

    /**
     * 社团审批分页查询

     * @return
     */
    @GetMapping("/page")
    @ApiOperation("社团审批分页查询")
    public Result getSimpleApprovalPage(ClubApprovalQueryDTO queryDTO) {
        Page<ClubApprovalVO> page = clubApplicationService.getApprovalPage(queryDTO);
        return Result.success(page);
    }
    /**
     * 根据社团记录表id查询社团的审批详细信息
     * @param Id
     * @return
     */
    @GetMapping("/{Id}")
    @ApiOperation("根据社团记录表id查询社团的审批详细信息")
    public Result getApprovalDetail(@PathVariable Long Id) {
         ClubApprovalDetailVO clubApprovalDetailVO = clubApplicationService.getApprovalDetail(Id);
        return Result.success(clubApprovalDetailVO);
    }

    /**
     * 处理社团审批
     * @param approvalId
     * @param isApproved
     * @param refuseReason
     *
     */
    @PostMapping("/{approvalId}/process")
    @ApiOperation("处理社团审批")
    public Result processApproval(@PathVariable Long approvalId, @RequestParam Boolean isApproved, @RequestParam(required = false) String refuseReason)
    {
        // 处理审批
        clubApplicationService.processApproval(approvalId, isApproved, refuseReason);
        return Result.success(isApproved ? "审批已通过" : "审批已拒绝");
    }

    }

